import time

import pymysql
from selenium import webdriver
from selenium.webdriver.common.by import By


class Login():
    def right_login(self, name, pwd, driver):
        time.sleep(1)
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

    def right_login_result(self, driver):
        return driver.find_element(By.ID, "logo").text

    def wrong_name_login(self, name, pwd, driver):
        time.sleep(1)
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

    def wrong_name_result(self, driver):
        return driver.find_element(By.XPATH, "//html/body/div/div/div/form/div[1]/span[1]").text

    def wrong_pwd_login(self, name, pwd, driver):
        time.sleep(1)
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

    def wrong_pwd_result(self, driver):
        return driver.find_element(By.XPATH, "//html/body/div/div/div/form/div[2]/span[1]").text


class SignUp():
    def signup(self, name, pwd, repwd, driver):
        driver.find_element(By.XPATH, '//html/body/div/div/div/div[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="username"]').send_keys(name)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="password"]').send_keys(pwd)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="repassword"]').send_keys(repwd)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        time.sleep(1)

    def signup_result(self, driver):
        url = driver.current_url
        if url != 'http://localhost:90/':
            driver.save_screenshot('signup1.jpg')
        return url

    def wrong_name(self, name, pwd, repwd, driver):
        driver.find_element(By.XPATH, '//html/body/div/div/div/div[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="username"]').send_keys(name)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="password"]').send_keys(pwd)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="repassword"]').send_keys(repwd)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        time.sleep(1)

    def wrong_name_result(self, driver):
        url = driver.current_url
        if url == 'http://localhost:90/':
            driver.save_screenshot('signup1.jpg')
        return url

    def wrong_repwd(self, name, pwd, repwd, driver):
        driver.find_element(By.XPATH, '//html/body/div/div/div/div[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="username"]').send_keys(name)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="password"]').send_keys(pwd)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="repassword"]').send_keys(repwd)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="login_btn"]').click()
        time.sleep(1)

    def wrong_repwd_result(self, driver):
        url = driver.current_url
        result = driver.find_element(By.XPATH, '//html/body/div/div/div/form/div[3]/span[1]').text
        return url, result


class Buy():
    def buy_lingqian(self, name, pwd, paywd, driver):
        time.sleep(1)
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/input').send_keys(paywd)
        time.sleep(2)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(0.5)

    def buy_lingqian_result(self, driver):
        result = driver.find_element(By.XPATH,
                                     '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        time.sleep(1)
        result_money = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]').text
        return result, result_money

    def buy_wrongpaywd(self, name, pwd, paywd, driver):
        time.sleep(1)
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/input').send_keys(paywd)
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)

    def buy_wrongpaywd_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def buy_nomoney(self, name, pwd, paywd, driver):
        time.sleep(1)
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/input').send_keys(paywd)
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)

    def buy_nomoney_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def buy_nocard(self, name, pwd, paywd, driver):
        time.sleep(1)
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/input').send_keys(paywd)
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[3]/a[1]').click()
        time.sleep(1)

    def buy_nocard_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text


class BuyQiXian():
    def buy_qixian(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button').click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//html/body/div[3]/div[2]/input').send_keys(paywd)

        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(0.5)

    def buy_qixian_result(self, driver):
        result = driver.find_element(By.XPATH,
                                     '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        time.sleep(1)
        result_money = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]').text
        return result, result_money

    def buy_wrongpaywd(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button').click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//html/body/div[3]/div[2]/input').send_keys(paywd)

        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(0.5)

    def buy_wrongpaywd_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def buy_nomoney(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button').click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//html/body/div[3]/div[2]/input').send_keys(paywd)

        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(0.5)

    def buy_nomoney_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def buy_nocard(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button').click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//html/body/div[3]/div[2]/input').send_keys(paywd)

        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(0.5)

    def buy_nocard_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text


class BuyJiJin():
    def buy_jijin(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//html/body/div[3]/div[2]/input').send_keys(paywd)

        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(0.5)

    def buy_jijin_result(self, driver):
        result = driver.find_element(By.XPATH,
                                     '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        time.sleep(1)
        result_money = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]').text
        return result, result_money

    def buy_wrongpaywd(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//html/body/div[3]/div[2]/input').send_keys(paywd)

        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(0.5)

    def buy_wrongpaywd_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def buy_nomoney(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//html/body/div[3]/div[2]/input').send_keys(paywd)

        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(0.5)

    def buy_nomoney_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def buy_nocard(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//html/body/div[3]/div[2]/input').send_keys(paywd)

        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(0.5)

    def buy_nocard_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text


class Pay():
    def pay(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/input').send_keys(paywd)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(1)

    def pay_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def default1(self, name, pwd, paywd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/input').send_keys(paywd)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(1)

    def default1_result(self, driver):
        result = driver.find_element(By.XPATH,
                                     '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        time.sleep(1)
        result_money = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]').text
        return result, result_money

    def default2(self, name, pwd, paywd, driver):
        # 改默认
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div[3]/div/div/div[1]/ul/li/button[3]').click()
        time.sleep(2)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/input').send_keys(paywd)
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]').click()
        time.sleep(1)

    def default2_result(self, driver):
        result = driver.find_element(By.XPATH,
                                     '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
        driver.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a').click()
        time.sleep(1)
        result_money = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]').text
        return result, result_money


class Borrow():
    def zhengchang(self, name, pwd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[2]/a').click()
        time.sleep(1)
        try:
            driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/h4')
            a = 0
        except:
            a = driver.find_element(By.XPATH,
                                    '/html/body/div/div/main/div/div/div/div/div[2]/div[2]/div[2]/div/button[6]/span').text
            a = int(a.strip('条'))
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
            '10000')
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
            '10')
        driver.find_element(By.XPATH, '//*[@id="submit"]').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(3)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[2]/a').click()
        time.sleep(1)
        return a

    def zhengchang_result(self, driver):
        newa = driver.find_element(By.XPATH,
                                   '/html/body/div/div/main/div/div/div/div/div[2]/div[2]/div[2]/div/button[6]/span').text
        newa = int(newa.strip('条'))
        return newa

    def shenpi(self):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys("lisi")
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys("123456")
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
            '10000')
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
            '10')
        driver.find_element(By.XPATH, '//*[@id="submit"]').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(3)
        driver.close()
        adminDriver = webdriver.Chrome()
        adminDriver.get("http://localhost:90")
        adminDriver.maximize_window()
        adminDriver.find_element(By.XPATH, "//input[@id='username']").send_keys("admin")
        adminDriver.find_element(By.XPATH, "//input[@id='password']").send_keys("123456")
        adminDriver.find_element(By.ID, "login_btn").click()
        time.sleep(1)
        adminDriver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[5]/a').click()
        time.sleep(1)
        adminDriver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[5]/ul/li[1]/a').click()
        time.sleep(1)
        adminDriver.find_element(By.XPATH,
                                 '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[7]/button[1]').click()
        time.sleep(1)
        adminDriver.find_element(By.XPATH,
                                 '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(1)
        adminDriver.close()

    def shenpi_result(self):
        connect = pymysql.connect(host='localhost', user='root', password='root', database='finance')
        cursor = connect.cursor()
        sql = "select username,id from user"
        cursor.execute(sql)
        x = cursor.fetchall()
        for i in range(len(x)):
            if 'lisi' in x[i - 1]:
                userid = x[i - 1][1]
        connect.commit()
        sql = f"select balance from bankcard where userId={userid} and defaultl=1"
        cursor.execute(sql)
        x = cursor.fetchall()
        money = x[0][0]
        print(money)
        return money
    def nocard(self, name, pwd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys(name)
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys(pwd)
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
            '10000')
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
            '10')
        driver.find_element(By.XPATH, '//*[@id="submit"]').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(3)

    def nocard_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def big(self, name, pwd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys("lisi")
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys("123456")
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
            '100000000000000000')
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
            '10')
        driver.find_element(By.XPATH, '//*[@id="submit"]').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(3)

    def big_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def small(self, name, pwd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys("lisi")
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys("123456")
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
            '10')
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
            '10')
        driver.find_element(By.XPATH, '//*[@id="submit"]').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(3)

    def small_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text

    def maxtime(self, name, pwd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys("lisi")
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys("123456")
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys('10')
        driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys('10000')
        driver.find_element(By.XPATH,'//*[@id="submit"]').click()
        time.sleep(0.5)

    def maxtime_result(self, driver):
        return driver.find_element(By.XPATH,'/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/span').text

    def time(self, name, pwd, driver):
        driver.maximize_window()
        driver.find_element(By.XPATH, "//input[@id='username']").send_keys("lisi")
        driver.find_element(By.XPATH, "//input[@id='password']").send_keys("123456")
        driver.find_element(By.ID, "login_btn").click()
        time.sleep(1)

        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[3]/ul/li[2]/a').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input').send_keys(
            '100')
        driver.find_element(By.XPATH,
                            '/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input').send_keys(
            '9999')
        driver.find_element(By.XPATH, '//*[@id="submit"]').click()
        time.sleep(1)
        driver.find_element(By.XPATH,
                            '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]').click()
        time.sleep(0.5)

    def time_result(self, driver):
        return driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div').text
